<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Home</title>
    <link rel="stylesheet" th:href="@{static/css/layui.css}">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">运动会管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">

        </ul>
        <ul class="layui-nav layui-layout-right">
            <div th:if="${session.user}">
                <li class="layui-nav-item">
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-user" style="font-size: 15px"></i>
                        <span th:text="${session.user.getNum()}">unknown</span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{userinfo}">基本资料</a></dd>
                        <dd><a th:href="@{/toPage(url=rePassword)}">修改密码</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="user/logout">退出</a></li>
            </div>
            <div th:unless="${session.user}">
                <li class="layui-nav-item"><a th:href="@{/toPage(url=login)}">登录</a></li>
            </div>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="test" style="margin-right: 10px;">
                <li class="layui-nav-item"><a href="/sports">主页</a></li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">当前赛况</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/toPage(url=scoreSituation)}">田赛</a></dd>
                        <dd><a th:href="@{/toPage(url=scoreSituationJ)}">径赛</a></dd>
                    </dl>
                </li>
                <div th:if="${session.user}">
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{/toPage(url=signup)}">我要报名</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('2')}"><a th:href="@{/toPage(url=myRegistration)}">我的报名</a></li>
                    <li class="layui-nav-item layui-nav-itemed" th:if="${session.user.getIdentity().equals('0') || session.user.getIdentity().equals('1')}">
                        <a href="javascript:;">上传成绩</a>
                        <dl class="layui-nav-child">
                            <dd><a th:href="@{/toPage(url=scoreEntryT)}">田赛</a></dd>
                            <dd><a th:href="@{/toPage(url=scoreEntryJ)}">径赛</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=registrationReview)}">报名审核</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=perManagement)}">人员管理</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=noticeManage)}">公告管理</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=volunteer)}">志愿者名单</a></li>
                    <li class="layui-nav-item" th:if="${session.user.getIdentity().equals('1')}"><a th:href="@{/toPage(url=projectManage)}">项目</a></li>
                </div>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->

        <div class="layui-row">
            <div class="layui-col-md4 layui-col-md-offset5">
                <h1 style="height: 70px;">我的报名</h1>
            </div>
        </div>

        <div class="layui-row">
            <span id="lll" style="left: 40%;color: lightseagreen"></span>
        </div>


        <div class="layui-row">
            <table id="myRegistration" lay-filter="myRegistration"></table>
        </div>

    </div>

    <script th:src="@{static/layui.js}"></script>
    <script th:src="@{static/jquery.js}"></script>

    <script>
        $.get("apply/findSelfVolunteer",function (result) {
            if (result == "success"){
                $("#lll").text("您已经是光荣的志愿者了")
            }
        })
    </script>

    <script>
        layui.use('element', function () {
            var element = layui.element;
        });
    </script>

    <script>
        layui.use('table', function () {

            var table = layui.table;
            var userId =
                //执行一个 table 实例
                table.render({
                    elem: '#myRegistration'
                    , url: 'apply/findSelfApply' //数据接口
                    , title: '报名表'
                    , limit: 20
                    , toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                    , cols: [
                        [                //表头
                            {type: 'checkbox', fixed: 'left'}
                            , {field: 'applyId', title: 'ID', width: 180, height: 50, sort: true, fixed: 'left'}
                            , {field: 'stuNum', title: '学号', width: 180}
                            , {field: 'stuName', title: '姓名', width: 190}
                            , {field: 'stuSex', title: '性别', width: 180, sort: true}
                            , {field: 'projectName', title: '报名项目', width: 180}
                            , {field: 'review', title: '审核状态（0为待审核,1为通过,2为未通过）', width: 400, sort: true}
                        ]
                    ]


                });

            //监听头工具栏事件
            table.on('toolbar(myRegistration)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id)
                    , data = checkStatus.data; //获取选中的数据
                switch (obj.event) {
                    case 'add':
                        window.location.href = "/sports/toPage?url=signup";
                        break;
                    case 'update':
                        layer.msg('本表不支持编辑操作');
                        break;
                    case 'delete':
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else if (data.length === 1) {
                            if ("1" == checkStatus.data[0].review || "2" == checkStatus.data[0].review) {
                                layer.msg('不能对此行数据操作');
                            } else {
                                layer.alert("确认要删除这行吗？", function () {
                                    $.post('apply/delete', {id: checkStatus.data[0].applyId}, function (result) {
                                        if (result == 'success') {
                                            window.location.reload();
                                        } else {
                                            layer.alert("删除失败")
                                        }
                                    }, "text");
                                });
                            }
                        } else {
                            layer.msg('不允许多行操作');
                        }
                        break;
                }
                ;
            });

            //监听行工具事件
            table.on('tool(myRegistration)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'detail') {
                    layer.msg('查看操作');
                } else if (layEvent === 'more') {
                    //下拉菜单
                    dropdown.render({
                        elem: this //触发事件的 DOM 对象
                        , show: true //外部事件触发即显示
                        , data: [{
                            title: '编辑'
                            , id: 'edit'
                        }, {
                            title: '删除'
                            , id: 'del'
                        }]
                        , click: function (menudata) {
                            if (menudata.id === 'del') {
                                layer.confirm('真的删除行么', function (index) {
                                    obj.del(); //删除对应行（tr）的DOM结构
                                    layer.close(index);
                                    //向服务端发送删除指令
                                });
                            } else if (menudata.id === 'edit') {
                                layer.msg('编辑操作，当前行 ID:' + data.id);
                            }
                        }
                        , style: 'margin-left: -50px; box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                    })
                }
            });


        });
    </script>

</body>
</html>
